﻿package mortal.game.scene3D.layer3D.utils
{
    import Message.Public.*;
    import com.gengine.debug.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.pools.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.scene3D.layer3D.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.player.item.*;

    public class PassUtil extends EntityLayerUtil
    {
        private var _passMap:PassDictionary;
        private var _isInitPassList:Boolean = false;
        private var notAddToStageDictionary:Dictionary;

        public function PassUtil(param1:PlayerLayer)
        {
            this._passMap = new PassDictionary();
            this.notAddToStageDictionary = new Dictionary();
            super(param1);
            return;
        }// end function

        private function addPassPoint(param1:SPassPoint) : PassPlayer
        {
            var _loc_2:* = this._passMap.getPass(param1.passPointId) as PassPlayer;
            if (_loc_2 == null)
            {
                _loc_2 = FrObjectPool.getObject(PassPlayer, this) as PassPlayer;
                this._passMap.addPass(param1.passPointId, _loc_2);
            }
            _loc_2.updatePassPoint(param1);
            Log.debug("增加传送阵:" + param1.name + "  " + [param1.point.x, param1.point.y]);
            layer.addChild(_loc_2);
            return _loc_2;
        }// end function

        public function initPassList() : void
        {
            return;
        }// end function

        public function removePassPoint(param1:int) : void
        {
            var _loc_2:* = this._passMap.removePass(param1);
            if (_loc_2)
            {
                _loc_2.parent = null;
                _loc_2.dispose();
            }
            return;
        }// end function

        public function getPass(param1:int) : PassPlayer
        {
            return this._passMap.getPass(param1);
        }// end function

        override public function removeAll() : void
        {
            this._passMap.removeAll();
            this._isInitPassList = false;
            return;
        }// end function

        public function updatePassIsAddToStage(param1:int, param2:Boolean) : void
        {
            if (!param2 && (param1 != 20036 && param1 != 20032 && param1 != 20038 && param1 != 20301))
            {
                this.notAddToStageDictionary[param1] = 1;
                ThingUtil.isMoveChange = true;
                Log.debug("隐藏传送阵：", param1);
            }
            else
            {
                delete this.notAddToStageDictionary[param1];
                ThingUtil.isMoveChange = true;
            }
            return;
        }// end function

        public function resetNotAddToStage() : void
        {
            this.notAddToStageDictionary = new Dictionary();
            return;
        }// end function

        public function isAddToStage(param1:SPassPoint) : Boolean
        {
            var _loc_2:* = param1.type == EMapPassPoint._EMapPassPointServerLimit;
            var _loc_3:* = param1.passPointId - int(param1.passPointId / 10) * 10;
            var _loc_4:* = Cache.instance.publicCache.innerServer == _loc_3;
            var _loc_5:* = Cache.instance.passCrossCache.isInPassCross(_loc_3);
            return !this.notAddToStageDictionary[param1.passPointId] && !(_loc_2 && !_loc_4);
        }// end function

        override public function updateEntity() : void
        {
            var _loc_2:PassPlayer = null;
            var _loc_3:Point = null;
            var _loc_4:SPassPoint = null;
            if (!Game.sceneInfo)
            {
                return;
            }
            var _loc_1:* = Game.sceneInfo.passInfos;
            if (_loc_1.length < 1)
            {
                return;
            }
            for each (_loc_4 in _loc_1)
            {
                
                if (SceneRange.isInScene(_loc_4.point.x, _loc_4.point.y) && this.isAddToStage(_loc_4))
                {
                    _loc_2 = this.getPass(_loc_4.passPointId);
                    if (_loc_2 == null)
                    {
                        _loc_2 = this.addPassPoint(_loc_4);
                    }
                    else if (_loc_2.parent == null)
                    {
                        layer.addChild(_loc_2);
                    }
                    continue;
                }
                this.removePassPoint(_loc_4.passPointId);
            }
            return;
        }// end function

        public static function isPassToCopyType(param1:SPassTo) : Boolean
        {
            if (param1.toPoint.x == 100000 || param1.toPoint.y == 100000)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPassToCrossServerMapType(param1:SPassTo) : Boolean
        {
            if (param1.toPoint.x == 100001 || param1.toPoint.y == 100001)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPassToCrossBossHodType(param1:SPassTo) : Boolean
        {
            if (param1.toPoint.x == 100002 || param1.toPoint.y == 100002)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPassToSameServerBossHodType(param1:SPassTo) : Boolean
        {
            if (param1.toPoint.x == 100003 || param1.toPoint.y == 100003)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPassToCrossMainCity(param1:SPassTo) : Boolean
        {
            if (param1.toPoint.x == 100004 || param1.toPoint.y == 100004)
            {
                return true;
            }
            return false;
        }// end function

    }
}
